"use strict";
const common_vendor = require("../../../common/vendor.js");
if (!Array) {
  const _easycom_up_line_progress2 = common_vendor.resolveComponent("up-line-progress");
  const _easycom_u_button2 = common_vendor.resolveComponent("u-button");
  const _easycom_up_picker2 = common_vendor.resolveComponent("up-picker");
  const _easycom_up_checkbox2 = common_vendor.resolveComponent("up-checkbox");
  const _easycom_up_checkbox_group2 = common_vendor.resolveComponent("up-checkbox-group");
  (_easycom_up_line_progress2 + _easycom_u_button2 + _easycom_up_picker2 + _easycom_up_checkbox2 + _easycom_up_checkbox_group2)();
}
const _easycom_up_line_progress = () => "../../../node-modules/uview-plus/components/u-line-progress/u-line-progress.js";
const _easycom_u_button = () => "../../../node-modules/uview-plus/components/u-button/u-button.js";
const _easycom_up_picker = () => "../../../node-modules/uview-plus/components/u-picker/u-picker.js";
const _easycom_up_checkbox = () => "../../../node-modules/uview-plus/components/u-checkbox/u-checkbox.js";
const _easycom_up_checkbox_group = () => "../../../node-modules/uview-plus/components/u-checkbox-group/u-checkbox-group.js";
if (!Math) {
  (_easycom_up_line_progress + _easycom_u_button + _easycom_up_picker + _easycom_up_checkbox + _easycom_up_checkbox_group)();
}
const _sfc_main = {
  __name: "PreConsult",
  setup(__props) {
    const newMessage = common_vendor.ref("");
    const messages = common_vendor.ref([]);
    const userGender = common_vendor.ref("");
    const showInput = common_vendor.ref(false);
    const showPicker = common_vendor.ref(true);
    const showOptions = common_vendor.ref(false);
    const showMultiSelect = common_vendor.ref(false);
    const columns = common_vendor.ref([
      ["男", "女"],
      Array.from({ length: 101 }, (_, i) => i.toString())
    ]);
    const selectedValue = common_vendor.ref([]);
    const options = common_vendor.ref([]);
    const multiSelectOptions = common_vendor.ref([]);
    const multiSelectValue = common_vendor.ref([]);
    const questions = [
      { text: "您的性别和年龄？", type: "picker", columns: [["男", "女"], Array.from({ length: 101 }, (_, i) => i.toString())] },
      { text: "您当前的身高（cm）体重（kg）是？", type: "picker", columns: [Array.from({ length: 41 }, (_, i) => `${(150 + i).toString()}cm`), Array.from({ length: 61 }, (_, i) => `${(40 + i).toString()}kg`)] },
      { text: "您当前的高压和低压（mmHg）为？", type: "picker", columns: [["不清楚", ...Array.from({ length: 101 }, (_, i) => `${(100 + i).toString()}mmHg`)], ["不清楚", ...Array.from({ length: 81 }, (_, i) => `${(50 + i).toString()}mmHg`)]] },
      { text: "您是否有过妊娠史？", type: "options", options: ["有", "当前正在孕期", "无"], condition: () => userGender.value === "女" },
      { text: "您是否患有以下疾病？（多选）", type: "multi-select", options: ["血脂异常", "脑血管病", "心脏疾病", "肾脏疾病", "周围血管病", "视网膜病变", "糖尿病", "不清楚", "无"] },
      { text: "请问您的心率为多少次/分钟？", type: "input" },
      { text: "请问您是否有以下症状（多选）", type: "multi-select", options: ["眼睑水肿", "夜尿增多", "血尿", "泡沫尿", "腹部肿块", "腰部及腹部血管性杂音", "不清楚", "无"] },
      { text: "请问您的总胆固醇为多少mmol/L？", type: "input" },
      { text: "请问您是否有以下症状（多选）", type: "multi-select", options: ["头晕", "眩晕", "视力下降", "感觉和运动异常", "不清楚", "无"] },
      { text: "请问您是否有以下症状（多选）", type: "multi-select", options: ["心悸", "胸痛", "心脏杂音", "下肢水肿", "不清楚", "无"] },
      { text: "请问您是否有以下症状（多选）", type: "multi-select", options: ["间歇性跛行", "四肢血压不对称", "脉搏异常", "血管杂音", "足背动脉搏动减弱", "不清楚", "无"] },
      { text: "请问您是否有早发心血管家族史（一级亲属发病年龄<50岁）？", type: "options", options: ["有", "无"] },
      { text: "请问您的直系亲属中是否有人患遗传疾病？", type: "options", options: ["有", "无"] },
      { text: "您是否有传染病史？", type: "multi-select", options: ["乙肝", "结核", "艾滋病", "不清楚", "无"] },
      { text: "您是否有食物过敏史？", type: "options", options: ["有", "无"] },
      { text: "请问您现在是否吸烟？", type: "options", options: ["是", "已戒烟", "否"] },
      { text: "请问您吸烟多久了？", type: "input", condition: () => messages.value[messages.value.length - 1].text === "是" },
      { text: "请问您每日的吸烟量？", type: "input", condition: () => messages.value[messages.value.length - 3].text === "是" },
      { text: "请问您的戒烟时长？", type: "input", condition: () => messages.value[messages.value.length - 1].text === "已戒烟" },
      { text: "请问您现在是否饮酒？", type: "options", options: ["是", "已戒酒", "否"] },
      { text: "请问您饮酒多久了？", type: "input", condition: () => messages.value[messages.value.length - 1].text === "是" },
      { text: "请问您每日的饮酒量？", type: "input", condition: () => messages.value[messages.value.length - 3].text === "是" },
      { text: "请问您的戒酒时长？", type: "input", condition: () => messages.value[messages.value.length - 1].text === "已戒酒" }
    ];
    const progressPercentage = common_vendor.ref(0);
    let currentQuestionIndex = 0;
    const updateProgress = () => {
      progressPercentage.value = currentQuestionIndex / questions.length * 100;
    };
    const nextQuestion = () => {
      let nextQuestion2 = questions[currentQuestionIndex];
      while (nextQuestion2.condition && !nextQuestion2.condition()) {
        currentQuestionIndex++;
        nextQuestion2 = questions[currentQuestionIndex];
      }
      if (nextQuestion2) {
        messages.value.push({ text: nextQuestion2.text, role: "system" });
        currentQuestionIndex++;
        updateProgress();
        switch (nextQuestion2.type) {
          case "picker":
            columns.value = nextQuestion2.columns;
            showPicker.value = true;
            showInput.value = false;
            showOptions.value = false;
            showMultiSelect.value = false;
            break;
          case "options":
            options.value = nextQuestion2.options;
            showPicker.value = false;
            showInput.value = false;
            showOptions.value = true;
            showMultiSelect.value = false;
            break;
          case "multi-select":
            multiSelectOptions.value = nextQuestion2.options;
            showPicker.value = false;
            showInput.value = false;
            showOptions.value = false;
            showMultiSelect.value = true;
            break;
          case "input":
            showPicker.value = false;
            showInput.value = true;
            showOptions.value = false;
            showMultiSelect.value = false;
            break;
        }
      } else {
        messages.value.push({ text: "所有问题已回答完毕", role: "system" });
        showInput.value = false;
        showPicker.value = false;
        showOptions.value = false;
        showMultiSelect.value = false;
        updateProgress();
      }
      common_vendor.nextTick$1(() => {
        const scrollView = document.querySelector(".chat-messages");
        scrollView.scrollTop = scrollView.scrollHeight;
      });
    };
    const confirmPicker = () => {
      const selectedText = selectedValue.value.join(", ");
      messages.value.push({ text: selectedText, role: "user" });
      if (questions[currentQuestionIndex - 1].text === "您的性别和年龄？") {
        userGender.value = selectedValue.value[0];
      }
      showPicker.value = false;
      nextQuestion();
    };
    const handleChange = (event) => {
      const { value } = event;
      selectedValue.value = value;
    };
    const handleMultiSelectChange = (event) => {
      console.log("multiSelectValue before change:", multiSelectValue);
      console.log("Event value:", event.value);
      multiSelectValue.value = event.detail.value;
    };
    const cancelPicker = () => {
      showPicker.value = false;
    };
    const selectOption = (option) => {
      messages.value.push({ text: option, role: "user" });
      showOptions.value = false;
      nextQuestion();
    };
    const confirmMultiSelect = () => {
      console.log("confirmMultiSelect called");
      console.log("Current multiSelectValue:", multiSelectValue.value);
      if (!Array.isArray(multiSelectValue.value)) {
        console.error("multiSelectValue.value is not an array");
        return;
      }
      const selectedText = multiSelectValue.value.join(", ");
      console.log("Selected Text to add to messages:", selectedText);
      messages.value.push({ text: selectedText, role: "user" });
      console.log("Updated messages array:", messages.value);
      showMultiSelect.value = false;
      nextQuestion();
    };
    const sendMessage = () => {
      if (newMessage.value.trim() === "")
        return;
      messages.value.push({ text: newMessage.value, role: "user" });
      newMessage.value = "";
      showInput.value = false;
      nextQuestion();
    };
    common_vendor.onMounted(() => {
      common_vendor.nextTick$1(() => {
        const scrollView = document.querySelector(".chat-messages");
        scrollView.scrollTop = scrollView.scrollHeight;
      });
      nextQuestion();
    });
    common_vendor.watch(currentQuestionIndex, () => {
      updateProgress();
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.p({
          percentage: progressPercentage.value,
          ["show-text"]: false,
          height: "20"
        }),
        b: common_vendor.f(messages.value, (message, index, i0) => {
          return {
            a: common_vendor.t(message.text),
            b: index,
            c: common_vendor.n(message.role)
          };
        }),
        c: showInput.value
      }, showInput.value ? {
        d: newMessage.value,
        e: common_vendor.o(($event) => newMessage.value = $event.detail.value),
        f: common_vendor.o(sendMessage),
        g: common_vendor.p({
          type: "primary"
        })
      } : showPicker.value ? {
        i: common_vendor.o(confirmPicker),
        j: common_vendor.o(handleChange),
        k: common_vendor.o(cancelPicker),
        l: common_vendor.p({
          show: true,
          columns: columns.value
        })
      } : showOptions.value ? {
        n: common_vendor.f(options.value, (option, index, i0) => {
          return {
            a: common_vendor.t(option),
            b: index,
            c: common_vendor.o(($event) => selectOption(option), index),
            d: "72bd485e-3-" + i0
          };
        }),
        o: common_vendor.p({
          type: "primary"
        })
      } : showMultiSelect.value ? {
        q: common_vendor.f(multiSelectOptions.value, (option, index, i0) => {
          return {
            a: common_vendor.t(option),
            b: index,
            c: "72bd485e-5-" + i0 + ",72bd485e-4",
            d: common_vendor.p({
              value: option
            })
          };
        }),
        r: common_vendor.o(handleMultiSelectChange),
        s: common_vendor.o(($event) => multiSelectValue.value = $event),
        t: common_vendor.p({
          modelValue: multiSelectValue.value
        }),
        v: common_vendor.o(confirmMultiSelect),
        w: common_vendor.p({
          type: "primary"
        })
      } : {}, {
        h: showPicker.value,
        m: showOptions.value,
        p: showMultiSelect.value
      });
    };
  }
};
wx.createPage(_sfc_main);
